package com.yexiao.cofe.business.controller;

import com.alibaba.fastjson2.JSONObject;
import com.yexiao.cofe.business.service.OrderService;
import com.yexiao.cofe.resolver.IRequestParam;
import com.yexiao.cofe.resolver.IRequestToken;
import com.yexiao.core.response.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author lkl
 * @since 2025/4/1
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    @PostMapping("/createOrder")
    public ResponseData createOrder(@RequestBody JSONObject param, @IRequestToken String token) {
        return ResponseData.success(orderService.createOrder(param, token));
    }

    @GetMapping("/listOrder")
    public ResponseData listOrder(@IRequestParam JSONObject param, @IRequestToken String token) {
        return ResponseData.success(orderService.listOrder(param, token));
    }

    @GetMapping("/modifyStatus")
    public ResponseData modifyStatus(@IRequestParam JSONObject param, @IRequestToken String token) {
        orderService.modifyStatus(param);
        return ResponseData.success();
    }

    @GetMapping("/detail")
    public ResponseData detail(@IRequestParam JSONObject param, @IRequestToken String token) {
        return ResponseData.success(orderService.detail(param, token));
    }

    @GetMapping("/pay")
    public ResponseData pay(@IRequestParam JSONObject param, @IRequestToken String token) {
        orderService.pay(param);
        return ResponseData.success("支付成功");
    }

    @GetMapping("/pick")
    public ResponseData pick(@IRequestParam JSONObject param, @IRequestToken String token) {
        orderService.pick(param);
        return ResponseData.success("取餐成功");
    }
}
